function FLogSavePlanet () {
    var server = top.FLogGetServer ();
    var facility = server.GetPlanet (window.userloc, "facility");

    facility["sector"] = POgetSector ();
    var coords = POgetCoords ();
    facility["coords"] = coords;
    facility["player_owned"] = "false";
    
    var spans = document.getElementsByTagName ("span");
    for (var i=0; i<spans.length; i++) {
        var style = spans[i].getAttribute ("style");
        if (!style) continue;
        
        if (style == "font-size:24px;font-weight:bold;") {
            facility["name"] = spans[i].textContent;
            try {
                var img = spans[i].parentNode.nextSibling.getElementsByTagName("img")[0].getAttribute ("src").split["/"];
                facility["planet_class"] = img[img.length-1].split(".")[0].split("_")[1].toUpperCase();
            } catch (e) {
                facility["planet_class"] = "???";
            }
            try {
                var img = spans[i].parentNode.previousSibling.getElementsByTagName("img")[0].getAttribute ("src").split("/");
                var fac = img[img.length-1].split(".")[0].split("_")[1];
                if (fac == "fed") facility["faction"] = "Federation";
                else if (fac == "uni") facility["faction"] = "Union";
                else facility["faction"] = "Empire";
            } catch (e) {
                facility["faction"] = "Neutral";
            }
            break;
        }
    }
    
    var tds = document.getElementsByTagName ("td");
    for (var i=0; i<tds.length; i++) {
        var td = tds[i];
        if (td.textContent == "Workers:") {
            td = td.nextSibling;
            facility["population"] = td.textContent.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        }
    }
    
    server.SaveFacility (window.userloc, facility, "facility");
}

FLogSavePlanet ();
